﻿/*
* @Author： whg
* @Date : 2021-1-19
* @Desc : 
*/
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using XNode;
public class ActorNode : BaseNode
{
    [Input(backingValue = ShowBackingValue.Always)]
    public BaseNode upLink;
    [Output(backingValue = ShowBackingValue.Always)]
    public BaseNode downLink;
    public override StringBuilder ToTable()
    {
        StringBuilder result = new StringBuilder(1024);
        string space = "				";
        result.Append(space + "{\n					type = Config.StoryConst." + actorType + ",\n");
        space += "	";
        switch (actorType)
        {
            case ActorType.ActorCreate:
                result.Append(space + "target = \"" + createTarget + "\",\n");
                if(Create_res_id!="")
                result.Append(space + "content = {\n"+space+"[\"" + Create_res_id + "\"]={res_id=" + Create_res_id + ",x=" + Create_pos.x + ",y=" + Create_pos.y + ",\n");
                if (Create_scale!=0)
                    result.Append(space+"scale=" + Create_scale +",\n" );
                if(Create_angle!=0)
                    result.Append(space + "angle=" + Create_angle + ",\n");
                result.Append(space + "},\n");
                if (special != "")
                    result.Append(space + "special = " + special + ",\n");
                break;
            case ActorType.ActorDelete:
                result.Append(space + "content = \"" + DeleteContent + "\",\n");
                break;
            case ActorType.ActorSetting:
                result.Append(space + "ins_id = " + Setting_ins_id + ",\n");
                result.Append(space + "position = {x=" + Setting_position.x + ",y=" + Setting_position.y + "},\n");
                result.Append(space + "angle = " + Setting_angle + ",\n");
                result.Append(space + "speed = " + Setting_speed + ",\n");
                break;
            case ActorType.ActorMove:
                result.Append(space + "mode = " + actorMoveType + ",\n");
                result.Append(space + "ins_id = " + Move_ins_id + ",\n");
                if (Move_speed != 0)
                    result.Append(space + "speed = " + Move_speed + ",\n");
                if (Move_rotate_speed != 0)
                    result.Append(space + "rotate_speed = " + Move_rotate_speed + ",\n");
                if (actorMoveType == ActorMoveType.寻路像素坐标)
                {
                    result.Append(space + "content = {x=" + Move_Point.x + ",y=" + Move_Point.y + "},\n");
                }
                else
                {
                    result.Append(space + "start_point = {x=" + Move_start_point.x + ",y=" + Move_start_point.y + ",z=" + Move_start_point.z + "},\n");
                    result.Append(space + "end_point = {x=" + Move_start_point.x + ",y=" + Move_start_point.y + ",z=" + Move_start_point.z + "},\n");
                    result.Append(space + "curve_list = \"" + Move_curve_list + "\",\n");
                    result.Append(space + "content = \"" + Move_content + "\",\n");
                }
                break;
            case ActorType.ActorRide:
                result.Append(space + "bool = " + isRide.ToString().ToLower() + ",\n");
                result.Append(space + "ins_id = \"" + Ride_ins_id + "\",\n");
                result.Append(space + "anim = \"" + Ride_anim + "\",\n");
                result.Append(space + "content = {id=\"" + Ride_id + "\",pos={x=" + Ride_pos.x + ",y=" + Ride_pos.y + ",z=" + Ride_pos.z + ",},\n rotate={x=" + Ride_rotate.x + ",y=" + Ride_rotate.y + ",z=" + Ride_rotate.z + "}},\n");
                break;
            case ActorType.ActorPlay:
                if (Play_precondition != "")
                    result.Append(space + "precondition = \"" + Play_precondition + "\",\n");
                result.Append(space + "ins_id = \"" + Play_ins_id + "\",\n");
                if (Play_wait)
                    result.Append(space + "wait = " + Play_wait.ToString().ToLower() + ",\n");
                string con = "";
                if (Play_end_animation)
                {
                    con = ",\nend_animation=" + Play_end_animation.ToString().ToLower();
                    result.Append(space + "content = {name=\"" + Play_name + "\",time=" + Play_time + con + ",}\n");
                }
                else
                    result.Append(space + "content = {name=\"" + Play_name + "\",time=" + Play_time + ",}\n");
                break;
            case ActorType.ActorAction:
                result.Append(space + "ins_id = \"" + Action_ins_id + "\",\n");
                result.Append(space + "attack = {content=" + Action_content + "},\n");
                break;
            case ActorType.ActorHide:
                if (Hide_wait)
                    result.Append(space + "wait = " + Hide_wait.ToString().ToLower() + ",\n");
                result.Append(space + "target = \"" + Hide_target + "\",\n");
                if (Hide_target == HideTarget.SapManager)
                {
                    result.Append(space + "ins_id = \"" + Hide_ins_id + "\",\n");
                    result.Append(space + "name = \"" + Hide_name + "\",\n");
                }
                result.Append(space + "bool = " + isHide.ToString().ToLower() + ",\n");
                break;
            case ActorType.ActorShadowMatrix:
                result.Append(space + "ins_id = \"" + ShadowMatrix_ins_id + "\",\n");
                result.Append(space + "x=" + ShadowMatrix_position.x + ",y=" + ShadowMatrix_position.y + ",z=" + ShadowMatrix_position.z + ",w=" + ShadowMatrix_position.w + ",\n");
                break;
        }
        result.Append("				},");
        return result;
    }
    public enum ActorType { ActorCreate, ActorDelete, ActorSetting, ActorMove, ActorRide, ActorPlay, ActorAction, ActorHide, ActorShadowMatrix }
    public ActorType actorType = ActorType.ActorCreate;

    #region ActorCreate
    public enum ActorCreateType { Actor, Effect, MainRole, Npc, Monster, GameObject }
    public ActorCreateType createTarget = ActorCreateType.Actor;
    [Tooltip("[id] = {instance_id,res_id,x,y,scale,angle,speed,rotate_speed}")]
    [TextArea]
    public string CreateContent;
    public string Create_res_id;
    public Vector2 Create_pos;
    public float Create_scale;
    public int Create_angle;
    [Tooltip("处理是根据性别,创建不同的模型")]
    [TextArea]
    public string special;
    #endregion

    #region ActorDelete
    [Tooltip("演员实例id列表，可多个")]
    [TextArea]
    public string DeleteContent;
    #endregion

    #region ActorSetting
    [Tooltip("演员实例id")]
    public string Setting_ins_id = "";
    public Vector2 Setting_position;
    public int Setting_angle;
    public int Setting_speed;
    #endregion

    #region ActorMove
    public enum ActorMoveType { 寻路像素坐标 = 1, 曲线运动 }
    [Tooltip("寻路（像素坐标）, 曲线运动")]
    public ActorMoveType actorMoveType = ActorMoveType.寻路像素坐标;
    public string Move_ins_id;
    [Tooltip("（选填）移动速度")]
    public float Move_speed;
    [Tooltip("（选填）转身速度")]
    public float Move_rotate_speed;
    [Tooltip("寻路坐标")]
    public Vector2 Move_Point;

    [Tooltip("起点")]
    public Vector3 Move_start_point;
    [Tooltip("终点")]
    public Vector3 Move_end_point;
    [Tooltip("曲线列表")]
    [TextArea]
    public string Move_curve_list;
    [TextArea]
    public string Move_content;
    #endregion

    #region ActorRide
    public bool isRide = true;
    [Tooltip("实例id")]
    public string Ride_ins_id;
    public string Ride_anim;
    [Tooltip("目标实例id")]
    public string Ride_id;
    [Tooltip("位置偏移")]
    public Vector3 Ride_pos;
    [Tooltip("旋转偏移")]
    public Vector3 Ride_rotate;
    #endregion

    #region ActorPlay
    public string Play_ins_id;
    public bool Play_wait;
    [Tooltip("前提条件(选填)，如ActorCreate")]
    public string Play_precondition;
    [Tooltip("动画名字")]
    public string Play_name = "casual";
    [Tooltip("播放动画时间")]
    public float Play_time = 1.333f;
    [Tooltip("播放结束动画")]
    public bool Play_end_animation;
    #endregion

    #region ActorAction
    public string Action_ins_id;
    [Tooltip("{content=20005458,--技能id}")]
    [TextArea]
    public string Action_content;
    #endregion

    #region ActorHide
    public enum HideTarget { MainRole, SapManager } 
    public bool Hide_wait = false;
    [Tooltip("目标类型 MainRole, SapManager")]
    public HideTarget Hide_target = HideTarget.MainRole;
    [Tooltip("(选填)SapManager类型")]
    public string Hide_ins_id;
    [Tooltip("(选填)SapManager类型")]
    public string Hide_name;
    public bool isHide = true;
    #endregion

    #region ActorShadowMatrix
    public string ShadowMatrix_ins_id;
    public Vector4 ShadowMatrix_position;
    #endregion
}
